import axios from 'axios';

import { Message } from 'element-ui';

const service = axios.create({
	baseURL: '/api', // api的base_url
	timeout: 6000, // 请求超时时间
	headers: {
		'X-Custom-Header': 'foobar',
		'Client-Type': 'mobile'
	}
})

// 请求拦截
service.interceptors.request.use(config => {
	config.headers.Authorization = 'token';
	return config;
}, error => Promise.reject(error))

// 响应拦截
service.interceptors.response.use(res => {
	console.log(res.data);
	return res.data; //统一把返回数据结果处理成res.data
}, error => {
	Message({
		showClose: true,
		message: '请求出错了！',
		type: 'error',
		duration: 5000
	});
	Promise.reject(error);
})

export default service;